<?php $this->headScript()->appendFile($this->js('plugins/jquery.blockUI.js'))?>
<script>
$(function(){

	$("#yearSemester, #select-grade, #stage").change(function(){
	    $("#listForm").submit();
	});
	$("#listTable img").click(function(){
	    var id = $(this).attr('id').substr(2);
	    if(id=='') return false;
	   $.blockUI();
	   $.getJSON('<?php echo $this->route("set-sendmit")?>',{id:id},function(data){
		   $.each(data,function(i,v){
		    if ($("#s-"+v.sn).hasClass('send-all'))
		    	$("#s-"+v.sn).attr('src','<?php echo $this->route('image')?>/file/yes.png').removeClass('send-all').addClass('yet-send-all');
		    else if ($("#s-"+v.sn).hasClass('yet-send-all'))
                $("#s-"+v.sn).attr('src','<?php echo $this->route('image')?>/file/key.png').removeClass('yet-send-all').addClass('send-all');
		    else if ($("#s-"+v.sn).hasClass('send-part'))
                $("#s-"+v.sn).attr('src','<?php echo $this->route('image')?>/file/zero.png').removeClass('send-part').addClass('yet-send-part');
		    else if ($("#s-"+v.sn).hasClass('yet-send-part'))
                $("#s-"+v.sn).attr('src','<?php echo $this->route('image')?>/file/oh.png').removeClass('yet-send-part').addClass('send-part');
		   });
		   $.unblockUI();
		});

	});

	$("#listTable tbody tr:even").addClass('even');
	$("#listTable tbody tr:odd").addClass('odd');
});
</script>
<style>
.even {background: #ffd}
.odd {background: #fff}
#listTable thead {background: #dee}
#listTable {background: #ccc; border-spacing:1px ;margin: 5px 2px}
#listTable td {text-align:center; padding:3px}
#listTable img {cursor: pointer;}
.helpdoc li {list-style-type: none;}
.helpdoc img{ margin:0 5px}
</style>
<div class="ui-widget">
<form action="" method="post" id="listForm" >
<select name="yearSemester" id="yearSemester">
<?php echo $this->YearSemesterOptions($this->yearSemester,array('order'=>'year DESC'))?>
</select>
<select id="select-grade" name="select-grade">
<option value=""><?php echo $this->translate('select grade ..')?></option>
<?php echo $this->ClassGradeOptions($this->selectGrade)?>
</select>
<?php if ($this->examineSet):?>
<select name="stage" id="stage">
<option value=""><?php echo $this->translate('choose stage ..')?></option>
<?php for($i=1; $i <= $this->examineSet->period; $i++):?>
<option value="<?php echo $i?>" <?php if($i==$this->stage):?>selected<?php endif?> ><?php echo sprintf($this->translate('%dth stage'),$i)?></option>
<?php endfor;?>
<option value="255" <?php if($this->stage==255):?>selected<?php endif?>><?php echo $this->translate('whole stage')?></option>
</select>
<?php endif?>
<?php if($this->stage==255) $cols=1;  else $cols=2;?>
<?php $flag = false;?>
<?php if ($this->semesterSubject):?>
<table  id="listTable" class="ui-widget-content">
<thead>
<tr>
<th rowspan="3" ><?php echo $this->translate('class name')?></th>
<?php foreach($this->semesterSubject as $scopeName=>$val):?>
<?php if (count($val) >1):?>
<?php $flag = true;?>
<th colspan="<?php echo count($val) *$cols ?>"><?php echo $scopeName?></th>
<?php else:?>
<th rowspan="2"   colspan="<?php echo $cols?>" ><?php echo $val[0]['name']?>
</th>
<?php endif;?>
<?php endforeach?>
</tr>

<tr>
<?php if ($flag):?>
<?php foreach($this->semesterSubject as $val):?>
<?php if (count($val) > 1):?>
<?php foreach($val as $row):?>
<th colspan="<?php echo $cols?>" ><?php echo $row['name']?>
</th>
<?php endforeach?>
<?php endif?>
<?php endforeach?>
<?php endif?>
</tr>

<?php if ($this->stage < 255):?>
<tr>
<?php foreach($this->semesterSubject as $val):?>
<?php foreach($val as $row):?>
<th><?php echo $this->translate('short name of regular score')?></th>
<th><?php echo $this->translate('short name of usually score')?></th>
<?php endforeach?>
<?php endforeach?>
</tr>
<?php endif?>

</thead>
<tbody>
<?php if ($this->className):?>
<?php foreach ($this->className as $id=>$val):?>
<?php foreach ($val as $classId=>$className):?>
<tr>
<td><?php echo $className?></td>
<?php foreach($this->semesterSubject as $val2):?>
<?php foreach($val2 as $val3):?>
<?php
// 階段成績
if ($this->stage < 255) {
    $si = 1; $ei=2;
}
else {
    // 全學期成績
    $si=3; $ei=3;
}

for ($i=$si;  $i<=$ei;  $i++) {
echo "<td>";
    if (isset($this->sendmitArr[$classId][$i][$val3['subject_sn']]['sendmit'])){
          $cc = $this->classStudentArr[$classId]-$this->sendmitArr[$classId][$i][$val3['subject_sn']]['count'];
        // 已傳送
        if ($this->sendmitArr[$classId][$i][$val3['subject_sn']]['sendmit'] == 'Y') {
            if ($cc==0)
            echo "<img class='send-all' id=\"s-".$this->sendmitArr[$classId][$i][$val3['subject_sn']]['sn']."\" src=\"". $this->route('image')."/file/key.png\" />";
            else
            echo "<img class='send-part' id=\"s-".$this->sendmitArr[$classId][$i][$val3['subject_sn']]['sn']."\" src=\"". $this->route('image')."/file/oh.png\" /> <br/> $cc";
        }
        // 未傳送
        else {
            if ($cc==0)
            echo "<img class='yet-send-all' id=\"s-".$this->sendmitArr[$classId][$i][$val3['subject_sn']]['sn']."\" src=\"". $this->route('image')."/file/yes.png\" />";
            else
            echo "<img class='yet-send-part' id=\"s-".$this->sendmitArr[$classId][$i][$val3['subject_sn']]['sn']."\" src=\"". $this->route('image')."/file/zero.png\" /> <br/> $cc";

        }
    }
    else
     echo "<img src=\"". $this->route('image')."/file/no.png\" />";
     echo  "</td>";
}
 ?>

<?php endforeach?>
<?php endforeach?>
</tr>
<?php endforeach?>
<?php endforeach?>
<?php endif;?>
</tbody>

</table>

<div class="helpdoc" style="margin: 5px auto">
<h3>相關說明</h3>
<ul>
    <li> <img src="<?php echo $this->route('image')?>/file/no.png" /> 全班成績都未輸入</li>
    <li> <img src="<?php echo $this->route('image')?>/file/zero.png" /> 部份學生成績未輸入，但未傳送到教務處</li>
    <li> <img src="<?php echo $this->route('image')?>/file/oh.png" /> 部份學生成績未輸入，但已傳送到教務處，按一下可開鎖</li>
    <li> <img src="<?php echo $this->route('image')?>/file/yes.png" /> 成績已經輸入，但未傳送到教務處，按一下可鎖定</li>
    <li> <img src="<?php echo $this->route('image')?>/file/key.png" /> 成績已經傳送到教務處並鎖定，按鑰匙打開鎖定，讓老師能重新上傳成績</li>
</ul>
</div>

<?php endif;?>
</form>
</div>